<link rel="stylesheet" type="text/css" href="css/validationEngine.jquery.css">
<link rel="stylesheet" type="text/css" href="css/template.css">

<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine.js"></script>
<script>

jQuery(document).ready(function($) {
jQuery("#formID").validationEngine();
});

</script>



<?php
$sql="SELECT substr( QUYEN,12, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 header('Location: index.php?page=s_tk'); 
	}
	else {
			echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
    
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="2" align="left" style="padding-bottom:10px;">QUẢN LÍ NGƯỜI DÙNG</th>
        </tr> 
        </thead>
        <tr valign="top" style="padding:5px;">
          <td width="47%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <?php  
	$sql="select * from qldl_tai_khoan where TEN_DANG_NHAP='".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else $row = @mysql_fetch_array($query);
		
  ?>    
  <form action="" method="post" name="formID" id="formID" enctype="multipart/form-data">
            <table width="100%" cellpadding="0" cellspacing="0" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="2"> Thông tin người dùng</th>
                </tr>
              <?php
			  if(isset($_POST['btn_edit_tk'])){
				  $email=$_POST['txt_email'];
				  $mkc=$_POST['txt_mkc'];
				  $mkm=$_POST['txt_mk_moi'];
				  $xnmk=$_POST['txt_xnmk'];
				  if($mkc=='' && $mkm=='' && $xnmk==''){
				  $sql1 = "update qldl_tai_khoan set				
								EMAIL='$email'
								where TEN_DANG_NHAP='".$_SESSION['username']."'";
	$query1 = @mysql_query($sql1,$conn); 
  
	if($query1){
		echo "<script>alert ('Cập nhật thông tin thành công.')</script>";	
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
					}
	else echo "<script>alert ('Lỗi cập nhật thông tin!')</script>";
				  }
				else if($mkc!='' && $mkm!='' && $xnmk!='') {
					$sql2="select * from qldl_tai_khoan where TEN_DANG_NHAP='".$_SESSION['username']."'";
					$query2 = @mysql_query($sql2,$conn);	
					$row2 = @mysql_fetch_array($query2);
					if($row2['MAT_KHAU']==$mkc){
						$sql3 = "update qldl_tai_khoan set				
								EMAIL='$email',
								MAT_KHAU='$mkm'
								where TEN_DANG_NHAP='".$_SESSION['username']."'";
						$query3 = @mysql_query($sql3,$conn); 
  
						if($query3){
						echo "<script>alert ('Cập nhật thông tin thành công.')</script>";	
						echo "<meta http-equiv='refresh' content='0;url= index.php'>";
					}
						else echo "<script>alert ('Lỗi cập nhật thông tin!')</script>";
						}
						else{
							echo "<script>alert ('Mật khẩu cũ không đúng.')</script>";	
							}
					} 
			  }
			  ?>
              </thead>
              <tbody>
              
                <tr>
                  <td width="154">Tên đăng nhập</td>
                  <td width="352"><input type="text" name="txt_tdn" id="txt_tdn" readonly="readonly" value="<?php echo $_SESSION['username'] ?>" /></td>
                </tr>
                <tr>
                  <td height="34">Email</td>
                  <td><input type="text" name="txt_email" id="txt_email" value="<?php echo $row['EMAIL']; ?>"/></td>
                  </tr>
                <tr>
                  <td colspan="2" align="center" style="font-weight:bold">Cập nhật mật khẩu</td>
                </tr>
                <tr>
                  <td>Nhập mật khẩu cũ</td>
                  <td><label for="textfield3"></label>
                    <input type="password" name="txt_mkc" id="textfield3" /></td>
                </tr>
                <tr>
                  <td>Mật khẩu mới</td>
                  <td><label for="textfield2"></label>
                    <input type="password" name="txt_mk_moi" id="txt_mk_moi" /></td>
                </tr>
                <tr>
                  <td>Xác nhận mật khẩu</td>
                  <td><label for="txt_mk_moi"></label>
                    <input type="password" name="txt_xnmk" id="txt_xnmk" class="validate[equals[txt_mk_moi]]" /></td>
                </tr>
                <tr>
                  <td colspan="2"><input type="submit" name="btn_edit_tk" id="btn_edit_tk" value="Lưu" />
                    <input type="reset" name="btn_huy" id="btn_huy" value="Hủy" />
                    <?php 
					if(isset($_POST['btn_add'])){
					$ht = $_POST['txt_ht'];
					$dc = $_POST['txt_dc'];
					$email = $_POST['txt_email'];
					$tdn = $_POST['txt_tdn'];
					$xnmk=$_POST['txt_xnmk'];
					$mk = $_POST['txt_mk'];
					
					$sql = "INSERT INTO qldl_tai_khoan VALUES('$tdn','$mk')";
	  				$query = @mysql_query($sql,$conn);
						if($query)echo "<p class='success_'>Thêm thông tin thành công.</p>";	
						else echo "<p class='error_'>Thêm không thành công!</p>";
					}
					?>
                    </td>
                  </tr>     
              </tbody>
            </table>
             </form>
          </div></td>
          
          <td width="53%" align="center">&nbsp;</td>
        </tr>
      </table>
    </div>
  </div>
</div>
